package com.google.code.irouter.batch.getter;

import java.util.ArrayList;
import java.util.List;

import com.google.code.irouter.batch.api.Detector;
import com.google.code.irouter.batch.api.DetectorResult;
import com.google.code.irouter.model.Guide;
import com.google.code.irouter.utils.ApiUtil;
import com.google.code.irouter.utils.LocalUtil;
import com.google.code.irouter.utils.LogUtil;

public final class InfoGetter {
	public static List<DetectorResult> execute(Guide guide) {
		List<DetectorResult> results = new ArrayList<DetectorResult>();
			try {
				String detectorName = ApiUtil.get(Detector.class.getSimpleName(), guide.getDetector()).getRefrence();
				Detector detector = (Detector) Class.forName(detectorName).newInstance();
				List<DetectorResult> detectorResults = detector.execute(guide);
				for(DetectorResult detectorResult : detectorResults)
					results.add(detectorResult);
			} catch (ClassNotFoundException exception) {
				LogUtil.error(LogUtil.TYPE.BATCH, InfoGetter.class, null, LocalUtil.getResource("com.google.code.irouter.batch.getter.relation.queue.infogetter.detector.unavailable") , exception);
			} catch (InstantiationException exception) {
				LogUtil.error(LogUtil.TYPE.BATCH, InfoGetter.class, null, LocalUtil.getResource("com.google.code.irouter.batch.getter.relation.queue.infogetter.detector.unavailable") , exception);
			} catch (IllegalAccessException exception) {
				LogUtil.error(LogUtil.TYPE.BATCH, InfoGetter.class, null, LocalUtil.getResource("com.google.code.irouter.batch.getter.relation.queue.infogetter.detector.unavailable") , exception);
			} catch (Exception exception) {
				LogUtil.error(
						LogUtil.TYPE.BATCH, 
						InfoGetter.class, 
						null,
						LocalUtil.getResource("i-router.batch.common.unknown"), 
						exception
				);
			}
		return results;
	}
}
